#include "RoomManager.h"

RoomManager* RoomManager::instance=nullptr;

RoomManager* RoomManager::getInstance(){
    if(instance==nullptr){
        instance=new RoomManager();
    }
    return instance;
}

bool RoomManager::addRoom(int roomId, std::unique_ptr<RoomBase> room) {
    if (!room || rooms.count(roomId)) {
        return false;
    }
    rooms[roomId] = std::move(room);
    return true;
}

bool RoomManager::removeRoom(int roomId) {
    return rooms.erase(roomId) > 0;
}

RoomBase* RoomManager::getRoom(int roomId) const {
    auto it = rooms.find(roomId);
    if (it != rooms.end()) {
        return it->second.get();
    }
    return nullptr;
}

std::vector<int> RoomManager::getAllRoomIds() const {
    std::vector<int> ids;
    ids.reserve(rooms.size());
    for (const auto& pair : rooms) {
        ids.push_back(pair.first);
    }
    return ids;
}

size_t RoomManager::size() const {
    return rooms.size();
}

